package com.leetcodehot.problems;

import java.util.ArrayList;
import java.util.List;

public class problems784 {
    private final List<String> res = new ArrayList<>();

    public List<String> letterCasePermutation(String s) {
        char[] c = s.toCharArray();
        int n = c.length;
        dfs(c, 0, n);
        return res;
    }

    private void dfs(char[] c, int i, int n) {
        if (i == n) {
            res.add(new String(c));
            return;
        }

        //不换
        dfs(c, i + 1, n);

        //换
        if ((c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z')) {
            c[i] = swapChar(c[i]);
            dfs(c, i + 1, n);
            c[i] = swapChar(c[i]);
        }
    }

    private char swapChar(char c) {
        if (c >= 'a' && c <= 'z') {
            c -= 32;
        } else if (c >= 'A' && c <= 'Z') {
            c += 32;
        }
        return c;
    }
}
